<?php

class Controller extends View {
	
	public $autoRender = true;
	
	public $useDB = false;
	
	public $langs = array(
		"de" => "Deutch",
		"sr" => "Srpski",
		"en" => "English"
	);
	
	public function __construct() {
		$this->init();
		parent::__construct();
	}
	
	public function init() {
		// load dbModel
		if($this->useDB){
			$modelName = "db".get_class($this);
			if(!$this->$modelName){
				$modelClassName = "Db".get_class($this);
				$this->$modelName = new $modelClassName();
			}
		}
		
		// load language specific strings
		if(isset($this->request->named["lang"])) {
			$_SESSION["language"] = strtolower($this->request->named["lang"]);
			$url = preg_replace('/\/lang\;[a-z]{2}/', '', $_SERVER["REQUEST_URI"]);
			$url = empty($url) ? "/" : $url;
			redirect($url);
		}elseif(empty($_SESSION["language"])){
			$_SESSION["language"] = DEFAULT_LOCALE;
		}
	}
	
	public function flashMessage(){
		$ret = "";
		if(!empty($_SESSION["flash-message"])){
			$this->set("flash_message", $_SESSION["flash-message"]);
			$this->set("flash_class", $_SESSION["flash-class"]);
			$ret = $this->fetch("flash");
			
			unset($_SESSION["flash-message"]);
			unset($_SESSION["flash-class"]);
		}
		return $ret;
	}
	
	public function flashSet($message, $class=""){
		$_SESSION["flash-message"] = $message;
		$_SESSION["flash-class"] = $class;
	}
}

?>